﻿using AutoMapper;
using MediatR;
using S_Gridding.Api.Application.Commands.Cellgrid;
using S_Gridding.Api.Application.Commands.Gridding;
using S_Gridding.Domains.FoundGridding;
using S_Gridding.Infrastructure.Interface.IWrite;

namespace S_Gridding.Api.Application.CommandsHanders.CellgridHanders
{
    public class CellgridCreateCommandsHanders : IRequestHandler<CellgridCreateCommands, int>
    {
        private readonly ICellgridRepository _cellgrid;
        private readonly IMapper _mapper;

        public CellgridCreateCommandsHanders(ICellgridRepository cellgrid, IMapper mapper)
        {
            _cellgrid = cellgrid;
            _mapper = mapper;
        }

        public async Task<int> Handle(CellgridCreateCommands request, CancellationToken cancellationToken)
        {
            var res = _mapper.Map<Cellgrid>(request);
            res.IsDel = false;
            return await _cellgrid.AddAsync(res);
        }
    }
}
